/**
 * 积分商城-今日任务
 */
'use strict';
import React, {
    Component
} from 'react'
import {
    Link
} from 'react-router'

import Header from './Common/Header'
import {
    HttpService,
    getLocalTime,
    Tips
} from '../Tools'
import imgErr from '../Img/other/splitGraphBig.png'


export default class companyIntro extends Component {

    componentWillMount() {
        this.getDetail()
    }
    //图片地址错误
    imgErr(e) {
        e.currentTarget.setAttribute('src', imgErr)
    }

    //获取详情
    getDetail() {
        HttpService.query({
            // url: '/src/data/integral/companyInfo.json',
            url: '/jf/company/get',
            async: false,
            data: {
                token: sessionStorage.appToken,
                companyId: this.props.params.id
            },
            success: (res => {
                if (res.code == 10140 && res.data) {
                    this.setState({
                        data: res.data
                    })
                }
            })
        })
    }

    render() {
        const {
            data
        } = this.state
        let {
            id,
            name,
            logo,
            address,
            linkPhone,
            businessType,
            introduce
        } = data
        introduce = decodeURIComponent(introduce)

        let unit = sessionStorage.userrole == '家长' ? '积分' : '荣誉值';
        return (
            <div className="companyintro">
                <Header title="商家介绍" />
                <img className='ctroimg' src={data.companyImgs} onError={this.imgErr.bind(this)} />
                <h5 className='ctroname'>{name}</h5>
                <div className='adtelstr bgc-white'>
                    <Link className='add' to={`/position/`+encodeURIComponent(escape(name))+`/${encodeURIComponent(escape(address.split('-')[3]))}/${address.split('-')[4]}/${address.split('-')[5]}`}>
                        {
                            address.split('-').map((item,index)=>{
                                if(index<4)
                                return item
                            })
                        }
                    </Link>
                    <a className='tel' href={`tel:${linkPhone}`} />
                </div>
                {introduce?<div className='ctrdetail' dangerouslySetInnerHTML={{__html:introduce}} />:null}
            </div>
        )
    }
}
